<?
	//$folder = extractNumberWithKeyFromArray('folder', $_REQUEST, null);
	if (!is_null($folder)) {
		$cmsDocument->addConstraint('organisationalname',$folder,'=');
	}
	$upUrl = $_SERVER['PHP_SELF'] . '?fileNo=1&formid=157';
	$returnURL = $_SERVER['PHP_SELF'] . "?fileNo=1&formid=130&sorts=clear&direction=clear&pageNumber=$pageNumber&folder=$folder";	
?>
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
<TD colSpan="5"><IMG height="10" src="/cms/images/spacer.gif" width="10" /></TD>
</TR>
<TR> 
<TD align="left" colSpan="5"><IMG height="7" src="/cms/images/spacer.gif" width="100%" /></TD>
</TR>
</table>

<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
  <TR>
    <TD>    
<?

	$width = 100;
	//extract the folderid..

	$cmsDocument->resetIterator();

	$resultSetCount = $cmsDocument->totalDocuments();
	if ( $resultSetCount > 0 ) {
		
		echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
		
			for($i=0; $i < $resultSetCount / 4; $i++ ) {
				echo "<tr>";
				for ($j = 0; $j < 4; $j++) {
				echo "<td width=\"25%\" valign=\"top\" align=\"left\">";
				if ($row = $cmsDocument->nextDocument()){
					$desc = magicClean($row->title);
					//since this is a constant type..
					// we can be lazy..
					if (!is_null($row->content)) {
						$downloadUrl = "/html/blob.php?attach=false&documentCode=" . $row->documentcode . '&scale=1&width=' . $width ;
					} else {
						$downloadUrl = "/cms/html/files/images/icon_imgbroken_lrg.gif";						
					}
					print <<< EOD
			<div class="wrap1">
			 <div class="wrap2">
			  <div class="wrap3">
EOD;
				if (editFormAuth($authInfo, $formDescription, $row->documentcode, $db)) {
					print <<< EOD
			   <a href="/cms/html/index.php?fileNo=101&documentCode=$row->documentcode&folder=$folder"><img width="$width" src="$downloadUrl" alt="$desc" /></a>
EOD;
				} else {

					print <<< EOD
			   <img width="$width" src="$downloadUrl" alt="$desc" />
EOD;
				}
			   		print <<< EOD
			  </div>
			 </div>
			</div>
EOD;

				} else {
					echo "&nbsp;";
				}
				echo"</td>"; 
			}
			echo "</tr>";
		}
	echo '</table>';
	} else {
		print <<< EOD
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<TR> 
<TD align="left" colSpan="5"><IMG height="7" src="/cms/images/greyline.gif" width="560" /></TD>
</TR>
<TR> 
<TD class="cms_browsetext" width="35"><img src="/cms/images/spacer.gif" height="20" /></TD>
<TD class="cms_browsetext" width="70">&nbsp;</TD>
<TD class="cms_browsetext" width="300"><I>There are no images in this folder.</I></TD>
<TD width="15">&nbsp;</TD>
<TD class="cms_browsetext" width="140">&nbsp;</TD>
</TR>
</table>	
EOD;
	}
?>
</TD>
</TR>
</TABLE>
<table cellpadding="0" cellspacing="0" width="100%" border="0">
                    <TR> 
                      <TD align="left" colSpan="4"><IMG height="7" src="/cms/images/greyline.gif" width="100%" /></TD>
                    </TR>
                    <TR> 
                      <TD class="cms_browsetext" width="35"><a href="<?= $upUrl ?>"><img src="/cms/html/files/images/icon_folderup.gif" width="35" height="20" /></a></TD>
                      <TD class="cms_browsetext" ><a href="<?= $upUrl ?>"><i>.. Back to parent folder.</i></a></TD>
                      <TD width="15"><IMG height="10" src="/cms/images/spacer.gif" width="10" />  </TD>
                      <TD class="cms_browsetext" width="140"></td>

                    <TR> 
                      <TD align="left" colSpan="4"><IMG height="7" src="/cms/images/greyline.gif" width="100%" /></TD>
                    </TR>
           
</table>
<?
	$addMode = CMS_ADD_QUICK_ADD_GO;
	$folderGid = null;
	if (!is_null($folder)) {
		$folderContent = $cmsDocument->openDocument($folder);
		if (!is_null($folderContent)) {
			$folderGid = $folderContent->gid;
		}
	}	
	//displayGoAdd($formDescription, $authInfo, $folderGid, array( 'fileNo'=>'2', 'formId'=>'130', 'organisationalname'=>$folder , 'returnURL' => urlencode($_SERVER['REQUEST_URI'])), $db);
	$addUrlDict = array(
			'fileNo'=>104,
			'formId'=> 130,
			'organisationalname'=>$folder,
			'returnURL' =>  $returnURL ,//return url in this is encoded when the input is written out.
			'gid' => $folderGid
	);	

?>